package com.irain.pp.account.service.redis.impl;

import com.irain.pp.account.service.dto.LoginInfo;
import com.irain.pp.account.repository.enums.VerifyCodeType;
import com.irain.pp.account.repository.model.PpUserDO;
import com.irain.pp.account.service.dto.VerifyCodeInfo;
import com.irain.pp.account.service.redis.PpUserRedisDao;
import com.irain.pp.tool.redis.template.BaseRedisDAO;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

/**
 * @author WangYanPeng
 * @date 2017/10/18 13:46
 */
@Component
public class PpUserRedisDaoImpl extends BaseRedisDAO<PpUserDO> implements PpUserRedisDao {

    private final static String H5_COOKIE = "h5Cookie";

    private final static String MOBILE = "mobile";

    @Override
    public void saveH5Cookie(String cookie, LoginInfo loginInfo, long expire){
        valueOps.set(genKey(H5_COOKIE,cookie),loginInfo,expire,TimeUnit.SECONDS);
    }

    @Override
    public LoginInfo getH5Cookie(String cookie){
        return (LoginInfo)valueOps.get(genKey(H5_COOKIE,cookie));
    }

    @Override
    public void saveVerifyCode(VerifyCodeType codeType, String mobile, VerifyCodeInfo verifyCodeInfo, long expire) {
        valueOps.set(genKey(MOBILE,codeType.name(),mobile), verifyCodeInfo, expire, TimeUnit.SECONDS);
    }

    @Override
    public VerifyCodeInfo getVerifyCode(VerifyCodeType codeType, String mobile) {
        return (VerifyCodeInfo) valueOps.get(genKey(MOBILE,codeType.name(), mobile));
    }
}
